<?php

namespace app\admin\controller\bdl\bd;
use app\admin\model\BdOrg;
use app\admin\model\Materialentry;
use app\common\controller\Backend;
use fast\Tree;
use think\Db;
use think\exception\DbException;
use think\exception\PDOException;
use think\exception\ValidateException;

/**
 *
 *
 * @icon fa fa-circle-o
 */
class Materialcate extends Backend
{
    /**
     * 模型对象
     * @var \app\admin\model\Materialcate
     */
    protected $model = null;

    protected $multiFields = '';

    public function _initialize()
    {
        parent::_initialize();

        $this->model = new \app\admin\model\Materialcate();

        $this->view->assign("fenableList", $this->model->getFenableList());
    }


    /**
     * 查看
     */
    public function index()
    {
        if ($this->request->isAjax())
        {
            $this->request->filter(['strip_tags', 'trim']);

            $filter = input('filter');
            $filter = json_decode($filter,true);
            if(!empty($filter))
            {
                $filter = array_key_exists('forgid',$filter);
                if(!$filter)
                {
                    $this->error('请先选择组织在进行查询');
                    die;
                }
            }else{
                $this->error('请先选择组织在进行查询');
                die;
            }
            list($where, $sort, $order, $offset, $limit) = $this->buildparams();

            $ruleDataList = $this->model->getRuleData($where);

            $ruleList = $ruleDataList['rulelist'];

            $total = $ruleDataList['total'] ?? count($ruleList);

            $result = array("total" => $total, "rows" => $ruleList);

            return json($result);
        }
        return $this->view->fetch();
    }


}